package com.dyz.leetcode._04_bitOperation;

public class _477_totalHammingDistance {
    public int totalHammingDistance(int[] nums) {
        //1的个数*（数组个数减去1的个数）
        int[] ch = new int[32];
        int n = nums.length;
        for(int num:nums){
            int i = 0;
            while(num>0){
                ch[i]+=(num&1);
                num=num>>1;
                i++;
            }
        }
        int res = 0;
        for(int k:ch){
            res+=k*(n-k);
        }
        return res;
    }
}
